
package servlets;

import beans.AlumnoMateriaBean;
import databeans.MateriaAlumnoDataBean;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Emerson
 */
public class AgregarMateriaAlumno extends HttpServlet {
   
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String urlAntes = request.getHeader("Referer");
        try {
            String[] materias = request.getParameterValues("materias");
            ArrayList <AlumnoMateriaBean> materias_alum= new ArrayList <AlumnoMateriaBean> ();
            String carnet=request.getParameter("carnet");
          
            for(int i=0; i <= materias.length - 1; i++){
                AlumnoMateriaBean aux = new AlumnoMateriaBean();
               
                aux.setCarnet(carnet);
                aux.setCodmateria(materias[i]);
                materias_alum.add(aux);
            }
            MateriaAlumnoDataBean mad= new MateriaAlumnoDataBean();
            mad.setMateriasAlumno(materias_alum);
            
            response.sendRedirect(urlAntes);


        } catch (Exception ex) {
            Logger.getLogger(AgregarMateriaAlumno.class.getName()).log(Level.SEVERE, null, ex);
            response.sendRedirect(urlAntes);
        } 
    } 

   
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

  
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

   
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
